package com.longcai.controller.homegood;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.longcai.bean.ApiResult;
import com.longcai.entity.homegood.ClyjGoodsSpec;
import com.longcai.service.homegood.ClyjGoodsSpecService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 商品规格表 前端控制器
 * </p>
 *
 * @author M
 * @since 2019-03-22
 */
@Controller
@RequestMapping("/clyjGoodsSpec")
public class ClyjGoodsSpecController {

    @Autowired
    private ClyjGoodsSpecService clyjGoodsSpecService;

    /**
     * 查询商品规格
     *
     * @param params
     * @return
     */
    @RequestMapping("/getGoodsSpec")
    @ResponseBody
    public ApiResult getGoodsSpec(@RequestBody JSONObject params) {
        String goodsid = params.getString("goodsid");
        if (StringUtils.isNotEmpty(goodsid) && !goodsid.equals("")) {
            return this.clyjGoodsSpecService.getGoodsSpec(goodsid);
        } else {
            return ApiResult.fail("商品id不能为空");
        }
    }

    /**
     * 查询商品规格
     *
     * @param params
     * @return
     */
    @RequestMapping("/getGoodsSpec2")
    @ResponseBody
    public ApiResult getGoodsSpec2(@RequestBody JSONObject params) {
        String goodsid = params.getString("goodsid");
        String specsid = params.getString("specsid");
        if (StringUtils.isNotEmpty(goodsid) && !goodsid.equals("")) {
            QueryWrapper<ClyjGoodsSpec> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("goods_id", goodsid);
            queryWrapper.eq("spec_id", specsid);
            List<ClyjGoodsSpec> list = this.clyjGoodsSpecService.selectList(queryWrapper);
            return ApiResult.success(list);
        } else {
            return ApiResult.fail("商品id不能为空");
        }
    }

    /**
     * 获取规格图片
     *
     * @param params
     * @return
     */
    @RequestMapping("/getSpecPics")
    @ResponseBody
    public ApiResult getSpecPics(@RequestBody JSONObject params) {
        String id = params.getString("id");
        if (id == null || id.equals("")) {
            return ApiResult.fail("查询失败");
        }
        return this.clyjGoodsSpecService.getSpecPics(id);

    }
}

